<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./TemplatePrincipal.xhtml">

            <ui:define name="top">
                <f:view>
                    <p:panel>
                        <p:clock mode="server" autoSync="true" pattern="HH:mm:ss dd/MM/yy" />
                    </p:panel>
                </f:view>
            </ui:define>

            <ui:define name="left">
                <f:view>
                    <h:form>
                        <p:panel>
                            <center>
                                <p:commandButton value="Register" action="StudentCreateEdit"
                                                 actionListener="#{studentBean.prepareNew}" id="registerButton" ajax="false"/>
                                <p:tooltip for="registerButton" value="Add New Student" />
                                <p:commandButton value="Back" action="PrincipalMenu" id="backButton" ajax="false">
                                    <p:tooltip for="backButton" value="Back main menu" />
                                </p:commandButton>
                            </center>
                        </p:panel>
                    </h:form>
                </f:view>
            </ui:define>

            <ui:define name="content">
                <p:panel>
                    <h1>
                    <p:outputLabel value="Student's List"/>
                    </h1>
                </p:panel>
                <f:view>
                    <h:form id="formulario">
                        <p:panel >
                                <p:dataTable value="#{studentBean.studentList}" var="item" paginator="true" rows="5">
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Control Number"/>
                                        </f:facet>
                                        <h:outputText value="#{item.controlNumber}"/>
                                    </p:column>
                                    <p:column filterBy="#{item.name}">
                                        <f:facet name="header">
                                            <h:outputText value="Name"/>
                                        </f:facet>
                                        <h:outputText value="#{item.name}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="First name"/>
                                        </f:facet>
                                        <h:outputText value="#{item.firstname}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Id Course"/>
                                        </f:facet>
                                        <h:outputText value="#{item.idCourse}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Edit"/>
                                        </f:facet>
                                        <center>
                                            <p:commandButton value="Edit" action="StudentCreateEdit" 
                                                             actionListener="#{studentBean.prepareEdit}"
                                                             id="editButton" >
                                                <f:setPropertyActionListener value="#{item}" target="#{studentBean.student}"/>
                                                <p:tooltip for="editButton" value="Edit selected student..."/>
                                            </p:commandButton>
                                        </center>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Delete"/>
                                        </f:facet>
                                        <center>
                                            <p:commandButton value="Delete" 
                                                             action="ConfirmStudent.xhtml" 
                                                             actionListener="#{studentBean.prepareRemove}"
                                                             id="deleteButton" ajax="false"/>
                                            <p:tooltip for="deleteButton" value="Delete selected student..."/>
                                        </center>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Details"/>
                                        </f:facet>
                                        <center>
                                            <p:commandButton value="See more" 
                                                             update=":formulario:panel" 
                                                             onclick="dialogo.show();" 
                                                             icon="ui-icon-info" 
                                                             id="seeButton">
                                                <p:tooltip for="seeButton" value="See More Details of selected student..."/>
                                                <f:setPropertyActionListener value="#{item}" target="#{studentBean.student}"/>
                                            </p:commandButton>
                                        </center>
                                    </p:column>
                                </p:dataTable>
                                <p:dialog widgetVar="dialogo" modal="true" width="250" 
                                          height="200" showEffect="fade" hideEffect="explode" 
                                          resizable="false" position="600 ,150" draggable="false">
                                    <h1><h:outputText value="Details..."/></h1>
                                    <h:panelGrid columns="2" id="panel">
                                        <p:outputLabel value="Id:"/>
                                        <p:outputLabel value="#{studentBean.student.id}" title="Id"/>
                                        <p:outputLabel value="Lastname:"/>
                                        <p:outputLabel value="#{studentBean.student.lastname}" title="Lastname"/>
                                    </h:panelGrid>
                                </p:dialog>
                        </p:panel>                                
                    </h:form>
                </f:view>
            </ui:define>
        </ui:composition>
    </body>
</html>
